package zoran.wang;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import zoran.wang.entity.Person;

/**
 * description：
 *
 * @author wangzhuo
 * @date 2022/3/16 22:24
 * @Email zoranwang@yeah.net
 */
public class SpringTest {

    ApplicationContext applicationContext;

    @Before
    public void beforeTest() {
        //获取Spring容器对象，由接口ApplicationContext表示，ClassPathXmlApplicationContext类路径src下
        applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

        //或者使用文件系统路径也可以
        FileSystemXmlApplicationContext fileSystemXmlApplicationContext =
                new FileSystemXmlApplicationContext("E:\\WorkSpace\\spring-demo\\spring-helloworld\\src\\applicationContext.xml");

    }

    /**
     * 测试获取到IOC容器中注入的对象
     */
    @Test
    public void test01() {

        //从容器中获取Bean对象
        Person p1 = (Person) applicationContext.getBean("p1");

        System.out.println(p1);

    }

}
